package com.example.demo2;

import android.content.Intent;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;




public class zcMainActivity extends AppCompatActivity {
    private EditText edit1,edit2,edit3;
    private Button but1;
    private TextView ttt;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zc_main);
        but1 = (Button) findViewById(R.id.but1);
        edit1 = (EditText) findViewById(R.id.edit1);
        edit2 = (EditText) findViewById(R.id.edit2);
        edit3 = (EditText) findViewById(R.id.edit3);
        ttt = (TextView)findViewById(R.id.ttt);


        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<username> list =  new ArrayList();
//                Bundle bbbund = new Bundle();
//                bbbund.putString("abc", edit2.getText().toString());
//                String adcc = bbbund.getString("abc" );
                String serch_textip=edit2.getText().toString().trim();
                    if ((edit2.getText().toString().equals(edit3.getText().toString())) && (edit2.getText().toString().equals("")==false)) {
                        int i;
                        String r = "2019585013";
                        int rd = Integer.parseInt(r);
                        Random j = new Random();
                        for (i = 0; i < 2; i++) {
                            r += j.nextInt(10);
                        }
                        for (i = 0; i < list.size(); i++) {
                            username ss = list.get(i);
                            if (ss.getId().equals(r)) {
                                i = 0;
                                r = "2019585013";
                                for (int k = 0; k < 2; k++) {
                                    r += j.nextInt(10);
                                }
                            }
                        }
                        username pp = new username();
                        Toast.makeText(zcMainActivity.this, "注册成功" + "\n" + "你的学号为" + r+"\n"+edit2.getText().toString(), Toast.LENGTH_LONG).show();
                        pp.setId(r);
                        //Toast.makeText(zcMainActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                        pp.setPassword(edit2.getText().toString());
                        pp.setName(edit3.getText().toString());
                        list.add(pp);
                        //int k;
                        //for (k=0;k<list.size();k++){
                        //username uss = list.get(k);
                        //ttt.setText(uss.getId()+"\n"+uss.getPassword()+"\n"+uss.getName());
                        //}
                        //list1.add(list);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("key", list);
                        Intent intent = new Intent(zcMainActivity.this, dtMainActivity.class);
                        intent.putExtras(bundle);
                        startActivityForResult(intent, 1);
                    } else {
                        Toast.makeText(zcMainActivity.this, "两次密码不一致请重新输入", Toast.LENGTH_SHORT).show();
                    }
            }

        });


    }
}
